package com.biglead.demo.rabbit.order.common;


import com.rabbitmq.client.AMQP;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class OrderMQSender {


    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(Object msg) {
        log.info("发送消息：{}", msg);
        rabbitTemplate.convertAndSend("fanoutExchange", "", msg);
    }

    /**
     * 秒杀订单走的消息队列
     * @param msg
     */

    public void sendSecKillMessage(String msg) {
        log.info("发送消息：{}", msg);
        //参数一 交换机名称
        //参数二 路由名称
        rabbitTemplate.convertAndSend("seckillExchange", "seckill.message", msg);
    }

    /**
     * 普通订单走的队列
     * @param msg
     */
    public void sendCommonOrderMessage(String msg) {
        log.info("预下单发送消息：{}", msg);
        rabbitTemplate.convertAndSend("commonOrderExchange", "commonOrder.message", msg);
    }

}
